/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.report.customer;

import java.util.Date;
import java.util.List;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
import src.domain.customer.Cusper;
import src.domain.customer.District;
import src.services.customer.CusperModel;
import src.services.customer.DistrictModel;

/**
 *
 * @author Yusup Jauhari Shandi <in.visi>
 */
public class RptDataNasabahDataSource implements JRDataSource{
    private int index = -1;
    
    private Object[][] data = {
			{ "Kode",new Date(),  "Nama", "Alamat","Kota","Male","022","081","202 College Av." }
			};
    /*
     * { "Chicago", new Integer(35), "George Karsen", "412 College Av." },
			{ "Chicago", new Integer(11), "Julia White", "412 Upland Pl." },
			{ "Dallas", new Integer(47), "Janet Fuller", "445 Upland Pl." },
			{ "Dallas", new Integer(43), "Susanne Smith", "2 Upland Pl." },
			{ "Dallas", new Integer(40), "Susanne Miller", "440 - 20th Ave." },
			{ "Dallas", new Integer(36), "John Steel", "276 Upland Pl." },
			{ "Dallas", new Integer(37), "Michael Clancy", "19 Seventh Av." },
			{ "Dallas", new Integer(19), "Susanne Heiniger", "86 - 20th Ave." },
			{ "Dallas", new Integer(10), "Anne Fuller", "135 Upland Pl." },
			{ "Dallas", new Integer(4), "Sylvia Ringer", "365 College Av." },
			{ "Dallas", new Integer(0), "Laura Steel", "429 Seventh Av." },
			{ "Lyon", new Integer(38), "Andrew Heiniger", "347 College Av." },
			{ "Lyon", new Integer(28), "Susanne White", "74 - 20th Ave." },
			{ "Lyon", new Integer(17), "Laura Ott", "443 Seventh Av." },
			{ "Lyon", new Integer(2), "Anne Miller", "20 Upland Pl." },
			{ "New York", new Integer(46), "Andrew May", "172 Seventh Av." },
			{ "New York", new Integer(44), "Sylvia Ott", "361 College Av." },
			{ "New York", new Integer(41), "Bill King", "546 College Av." },
			{ "Oslo", new Integer(45), "Janet May", "396 Seventh Av." },
			{ "Oslo", new Integer(42), "Robert Ott", "503 Seventh Av." },
			{ "Paris", new Integer(25), "Sylvia Steel", "269 College Av." },
			{ "Paris", new Integer(18), "Sylvia Fuller", "158 - 20th Ave." },
			{ "Paris", new Integer(5), "Laura Miller", "294 Seventh Av." },
			{ "San Francisco", new Integer(48), "Robert White", "549 Seventh Av." },
			{ "San Francisco", new Integer(7), "James Peterson", "231 Upland Pl." } 
     */
    
    List<Cusper> cuspers;
    DistrictModel helperDistrict;
    
    public RptDataNasabahDataSource() {
        super();
        CusperModel helper = new CusperModel();
        helperDistrict = new DistrictModel();
        //List<Cusper> list = helper.findAll(null);
        //for (list : obj){
            
        cuspers = helper.findAll(null);
        
    }
    
    
    
    @Override
    public boolean next() throws JRException {
        index++;
        //return (index < data.length);
        return (index < cuspers.size());
    }

    @Override
    public Object getFieldValue(JRField jrf) throws JRException {
       Object value = null;
/*<field name="customer_code" class="java.lang.String"/>
	<field name="registered_date" class="java.util.Date"/>
	<field name="customer_name" class="java.lang.String"/>
	<field name="id_address_line1" class="java.lang.String"/>
	<field name="city_name" class="java.lang.String"/>
	<field name="sex" class="java.lang.String"/>
	<field name="phone" class="java.lang.String"/>
	<field name="mobile_phone" class="java.lang.String"/>
        
        switch (fieldName) {
            case "customer_code": value = data[index][0]; break;
            case "registered_date": value = data[index][1];break;
            case "customer_name": value = data[index][2];break;
            case "id_address_line1":value = data[index][3];break;
            case "city_name":value = data[index][4];break;
            case "sex":value = data[index][5];break;
            case "phone":value = data[index][6];break;
            case "mobile_phone":value = data[index][7];break;
        }
        
        */
		String fieldName = jrf.getName();
        switch (fieldName) {
            case "customer_code": value = cuspers.get(index).getCustomer().getCif(); break;
            case "registered_date": value = cuspers.get(index).getCustomer().getRegisteredDate();break;
            case "customer_name": value = cuspers.get(index).getCustomer().getCustomerName();break;
            case "id_address_line1":value = cuspers.get(index).getCustomer().getIdAddressLine1();break;
            case "city_name":
                    District district =  helperDistrict.getById(cuspers.get(index).getCustomer().getIdDistrictId());
                    if (district!=null)    
                        value = district.getDistrictName();
                        //(cuspers.get(index).getCustomer().getIdDistrictId()!=null?cuspers.get(index).getCustomer().getIdDistrictId():-1));break;//cuspers.get(index).getCustomer().getIdDistrictId();break;
                        else value = null;
                break;
            case "sex":value = cuspers.get(index).getSex().toString();break;
            case "phone":value = cuspers.get(index).getCustomer().getPhone();break;
            case "mobile_phone":value = cuspers.get(index).getCustomer().getMobilePhone();break;
        }

		return value;
    }
    
}
